//
//  YYGradeVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/9.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYGradeVC.h"
#import "YYGradeCell.h"
#import "YYGradeCell2.h"

@interface YYGradeVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSArray * dataArr;
@property (nonatomic,strong)NSArray * dataArr2;

@end

@implementation YYGradeVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    if (@available(iOS 11.0, *)) {//解决隐藏导航栏scrollView不能到顶的问题
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    self.bgView.layer.shadowOffset = CGSizeMake(1, 1);
    self.bgView.layer.shadowOpacity = 0.8;
    self.bgView.layer.shadowColor = [UIColor colorWithWhite:0.7 alpha:1].CGColor;
}

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)getData{
    [RequestOperationManager personalIndexdetail_success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            self.dataArr = result[@"data"][@"list"][@"list"];
            self.dataArr2 = result[@"data"][@"list"][@"content"];
            [self.tableView2 reloadData];
            self.lb11.text = [NSString stringWithFormat:@"%@会员",self.dataArr[0][@"grade"]];
             self.lb1.text = [NSString stringWithFormat:@"%@积分",self.dataArr[0][@"integral"]];
             self.lb2.text = [NSString stringWithFormat:@"%@积分",self.dataArr[1][@"integral"]];
             self.lb22.text = [NSString stringWithFormat:@"%@会员",self.dataArr[1][@"grade"]];
             self.lb3.text = [NSString stringWithFormat:@"%@积分",self.dataArr[2][@"integral"]];
             self.lb33.text = [NSString stringWithFormat:@"%@会员",self.dataArr[2][@"grade"]];
        
            [self.rollImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",DEF_INTERFACE_WEBVIEWSERVICE,result[@"data"][@"roll"][@"image"]]] placeholderImage:DEF_IMAGENAME(@"member_bg")];
        }
    } failture:^(NSError *error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return self.dataArr2.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        YYGradeCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"YYGradeCell2"];
         NSDictionary * itme = self.dataArr2[indexPath.row];
        cell.lbTitle.text = itme[@"grade"];
        cell.lbContent.text = itme[@"content"];
        return cell;
  
}
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell
                                                            *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    if ([tableView isEqual:self.tableView2]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.bottmrTableHeight.constant =  tableView.contentSize.height;
            
        });
    }
}

-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSArray array];
    }
    return _dataArr;
}

-(NSArray *)dataArr2{
    if (!_dataArr2) {
        _dataArr2 = [NSArray array];
    }
    return _dataArr2;
}

@end
